home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / XDETECT.ASM < prev    next >
Assembly Source File  |  1993-08-31  |  8KB  |  269 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XDETECT
  3. ;
  4. ; Hardware detection module
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ;
  14. ; egg@dstos3.dsto.gov.au
  15. ; teg@bart.dsto.gov.au
  16. ;-----------------------------------------------------------------------
  17. LOCALS
  18. .286
  19.  
  20. include model.inc
  21. include xdetect.inc
  22.  
  23.     .data
  24.  
  25. _MouseButtonCount dw 0
  26. _MouseVersion     dw 0
  27. _MouseType        db 0
  28. _MouseIRQ         db 0
  29.  
  30.     .code
  31.  
  32.  
  33. i86       equ 0
  34. i186      equ 1
  35. i286      equ 2
  36. i386sx    equ 3
  37. i386dx    equ 4
  38. i486      equ 5
  39.  
  40.  
  41. NONE      equ 0
  42. MDA       equ 1
  43. CGA       equ 2
  44. EGAMono   equ 3
  45. EGAColor  equ 4
  46. VGAMono   equ 5
  47. VGAColor  equ 6
  48. MCGAMono  equ 7
  49. MCGAColor equ 8
  50.  
  51. PS2_CARDS db  0,1,2,2,4,3,2,5,6,2,8,7,8
  52.  
  53.  
  54. ;-----------------------------------------------------------------------
  55. ; PC Graphics detection routine. Returns graphics card type
  56. ;
  57. ; C callable as:
  58. ;    unsigned int x_graphics_card();
  59. ;
  60. ;
  61.  
  62. proc _x_graphics_card
  63.     push bp                  ; Preserve caller's stack frame
  64.     mov  bp,sp
  65.     mov  ax,1A00h            ; Try calling VGA Identity Adapter function
  66.     int  10h
  67.     cmp  al,1Ah              ; Do we have PS/2 video bios ?
  68.     jne  @@not_PS2           ; No!
  69.  
  70.     cmp  bl,0Ch              ; bl > 0Ch => CGA hardware
  71.     jg   @@is_CGA            ; Jump if we have CGA
  72.     xor  bh,bh
  73.     xor  ah,ah
  74.     mov  al,cs:PS2_CARDS[bx] ; Load ax from PS/2 hardware table
  75.     jmp  short @@done        ; return ax
  76. @@is_CGA:
  77.     mov  ax,CGA              ; Have detected CGA, return id
  78.     jmp  short @@done
  79. @@not_PS2:                       ; OK We don't have PS/2 Video bios
  80.     mov  ah,12h              ; Set alternate function service
  81.     mov  bx,10h              ; Set to return EGA information
  82.     int  10h                 ; call video service
  83.     cmp  bx,10h              ; Is EGA there ?
  84.     je   @@simple_adapter    ; Nop!
  85.     mov  ah,12h              ; Since we have EGA bios, get details
  86.     mov  bl,10h
  87.     int  10h
  88.     or   bh,bh               ; Do we have colour EGA ?
  89.     jz   @@ega_color         ; Yes
  90.     mov  ax,EGAMono          ; Otherwise we have Mono EGA
  91.     jmp  short @@done
  92. @@ega_color:
  93.     mov  ax,EGAColor         ; Have detected EGA Color, return id
  94.     jmp  short @@done
  95. @@simple_adapter:
  96.     int  11h                 ; Lets try equipment determination service
  97.     and  al,30h
  98.     shr  al,4
  99.     xor  ah,ah
  100.     or   al,al               ; Do we have any graphics card at all ?
  101.     jz   @@done              ; No ? This is a stupid machine!
  102.     cmp  al,3                ; Do We have a Mono adapter
  103.     jne  @@is_CGA            ; No
  104.     mov  ax,MDA              ; Have detected MDA, return id
  105. @@done:
  106.     pop  bp                  ;restore caller's stack frame
  107.     ret
  108. _x_graphics_card endp
  109.  
  110.  
  111. ;-----------------------------------------------------------------------
  112. ; PC Processor detection routine
  113. ;
  114. ; C callable as:
  115. ;    unsigned int x_processor();
  116. ;
  117. ;
  118. proc _x_processor
  119.     push bp
  120.     mov  bp,sp
  121.     pushf                    ; Save flags
  122.     xor  ax,ax         ; Clear AX
  123.     push ax                  ; Push it on the stack
  124.     popf                     ; Zero the flags
  125.     pushf                    ; Try to zero bits 12-15
  126.     pop  ax                  ; Recover flags
  127.         and  ax,0F000h           ; If bits 12-15 are 1 => i86 or i286
  128.         cmp  ax,0F000h
  129.         jne  @@1
  130.  
  131.         push cx                  ; save CX
  132.         mov  ax,0FFFFh           ; Set all AX bits
  133.         mov  cl,33               ; Will shift once on 80186
  134.         shl  ax,cl               ; or 33 x on 8086
  135.         pop  cx
  136.         mov  ax,i186
  137.         jnz  @@done
  138.         mov  ax,i86              ; 0 => 8086/8088
  139.         jmp  short @@done
  140.  
  141. @@1:
  142.         mov  ax,07000h           ; Try to set bits 12-14
  143.         push ax
  144.         popf
  145.         pushf
  146.         pop  ax
  147.         and  ax,07000h           ; If bits 12-14 are 0 => i286
  148.         mov  ax,i286
  149.         jz   @@done
  150.  
  151.         ;; 386/486 resolution code taken from WHATCPU.ASM by
  152.         ;; Dave M. Walker
  153.  
  154.  
  155.         P386
  156.         mov  eax,cr0
  157.         mov  ebx,eax                 ;Original CR0 into EBX
  158.         or   al,10h                  ;Set bit
  159.         mov  cr0,eax                 ;Store it
  160.         mov  eax,cr0                 ;Read it back
  161.         mov  cr0,ebx                 ;Restore CR0
  162.         test al,10h                  ;Did it set?
  163.         mov  ax,i386sx
  164.         jz   @@done                  ;Jump if 386SX
  165.  
  166.        ;*** Test AC bit in EFLAGS (386DX won't change)
  167.         mov     ecx,esp                 ;Original ESP in ECX
  168.         pushfd                          ;Original EFLAGS in EBX
  169.         pop     ebx
  170.         and     esp,not 3               ;Align stack to prevent 486
  171.                                         ;  fault when AC is flipped
  172.         mov     eax,ebx                 ;EFLAGS => EAX
  173.         xor     eax,40000h              ;Flip AC flag
  174.         push    eax                     ;Store it
  175.         popfd
  176.         pushfd                          ;Read it back
  177.         pop     eax
  178.         push    ebx                     ;Restore EFLAGS
  179.         popfd
  180.         mov     esp,ecx                 ;Restore ESP
  181.         cmp     eax,ebx                 ;Compare old/new AC bits
  182.         mov     ax,i386dx
  183.         je      @@done
  184. is_486:                                 ;Until the Pentium appears...
  185.         mov   ax,i486
  186. @@done:
  187.     popf
  188.         .286
  189.     pop  bp
  190.     ret
  191. _x_processor endp
  192.  
  193. .8086
  194. ;-----------------------------------------------------------------------
  195. ; PC Numeric coprocessor detection routine
  196. ;
  197. ; C callable as:
  198. ;    unsigned int x_coprocessor();
  199. ;
  200. ;  Based on an article in PC Tech Journal, Aug 87 by Ted Forgeron
  201. ;
  202. ;  Returns 1 if coprocessor found, zero otherwise
  203.  
  204. _x_coprocessor   proc
  205. ARG     control:word=StkSize
  206.     push   bp
  207.     mov    bp,sp
  208.     sub    sp,StkSize
  209.  
  210.     fninit                          ; try to initialize the copro.
  211.     mov    [control],0              ; clear control word variable
  212.         fnstcw control                  ; put control word in memory
  213.     mov    ax,[control]             ;
  214.     cmp    ah,03h                   ; do we have a coprocessor ?
  215.     je     @@HaveCopro              ; jump if yes!
  216.     xor    ax,ax                    ; return 0 since nothing found
  217.     jmp    short @@done
  218. @@HaveCopro:
  219.     mov    ax,1
  220. @@done:
  221.     mov    sp,bp
  222.     pop    bp
  223.     ret
  224. _x_coprocessor   endp
  225.  
  226.  
  227. ;-----------------------------------------------------------------------
  228. ; PC Mouse Driver detection routine
  229. ;
  230. ; C callable as:
  231. ;    unsigned int x_mousedriver();
  232. ;
  233. ;
  234. ;  Returns 1 if mouse driver found, zero otherwise
  235. _x_mousedriver proc
  236.            push bp
  237.            mov  bp,sp
  238.            mov  ax,3533h        ; Get int 33 interrupt vector
  239.            int  21h             ; Call dos
  240.            xor  cx,cx           ; Clear "found" flag
  241.            mov  ax,es           ; Is the vector null (ES==0 && BX==0) ?
  242.            or   bx,ax
  243.            jz   @@NoMouseDriver ; Yes! No mouse driver installed - Jump
  244.  
  245.            ; Just make absolutely sure the vector points to the mouse
  246.            ; driver (just in case)
  247.  
  248.            xor  ax,ax           ; FUNC 0: Mouse Initialization
  249.            int   33h
  250.            or    ax,ax          ; Do we have an installed mouse driver ?
  251.            jz    @@NoMouseDriver; No ?
  252.            mov   [_MouseButtonCount],bx
  253.  
  254.            mov   ax,24h
  255.            int   33h
  256.            mov   [_MouseVersion],bx
  257.            mov   [_MouseType],ch
  258.            mov   [_MouseIRQ],cl
  259.  
  260.            mov  cx,1            ; Yes! set flag
  261.  
  262. @@NoMouseDriver:
  263.            mov  ax,cx           ; Return "found" flag
  264.            pop  bp
  265.            ret
  266. _x_mousedriver endp
  267.  
  268.  
  269. end